package 二叉树相关问题.BST;

public class 二叉搜索树的后序遍历序列 {

    public boolean verifyPostorder(int[] postorder) {
        return method(postorder,0,postorder.length-1);
    }
    private boolean method(int[] postorder, int i, int j) {
        if (i>=j)
            return true;
        int p = i;
        //找到左子树
        while (postorder[p]<postorder[j])
            p++;
        int m=p;
        while (postorder[p]>postorder[j])
            p++;
        return p==j && method(postorder,i,m-1)  && method(postorder,m,j-1);
    }
}
